package com.tuling.code.jvm.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class FutureCallable implements Callable<String> {

	@Override
	public String call() throws Exception {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < 4; i++) {
			sb.append("我空是只猴子").append(i);
		}
		return sb.toString();
	}

	public static void main(String[] args) {
		FutureTask<String> future = new FutureTask<>(new FutureCallable());
		new Thread(future).start();

		try {
			//Thread.sleep(5000);// 可能做一些事情
			System.out.println(future.get());
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (ExecutionException e) {
			e.printStackTrace();
		}
	}
}
